package guowei.gulicart.vo;

import java.math.BigDecimal;
import java.util.List;

/**
 * 购物车属性
 */
public class Cart {

    private List<CartItem> items;   //各个商品属性

    private Integer countNum;   //商品总数量

    private Integer countType;  //商品类型数量

    private BigDecimal totalAmount; //购物车里所有商品总价

    private BigDecimal reduce = new BigDecimal("0");  //商品减免价格

    public List<CartItem> getItems() {
        return items;
    }

    public void setItems(List<CartItem> items) {
        this.items = items;
    }

    public Integer getCountNum() {
        Integer counts = 0;
        if (items != null){
            for (CartItem item : items) {
                counts += item.getCount();
            }
        }
        return counts;
    }

    public Integer getCountType() {
        Integer types = 0;
        if (items != null){
            for (CartItem cartItem:items){
                types += 1;
            }
        }
        return types;
    }

    public BigDecimal getTotalAmount() {
        BigDecimal totalPrice = new BigDecimal(0);
        if (items != null){
            for (CartItem item:items){
                    if (item.getCheck()){
                        totalPrice = totalPrice.add(item.getTotalPrice());
                    }
            }
        }
        totalPrice = totalPrice.subtract(getReduce());
        return totalPrice;
    }


    public BigDecimal getReduce() {
        return reduce;
    }

    public void setReduce(BigDecimal reduce) {
        this.reduce = reduce;
    }
}
